package nl.boelen.game.handler;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import nl.boelen.game.Game;
import nl.boelen.game.graphics.Screen;
import nl.boelen.game.handler.keys.BasicKey;
import nl.boelen.game.handler.keys.Key;
import nl.boelen.game.handler.keys.PauseKey;

public class keyboardHandler implements KeyListener {
    public Key up = new BasicKey("upArrow");
    public Key down = new BasicKey("downArrow");
    public Key left = new BasicKey("leftArrow");
    public Key right = new BasicKey("rightArrow");
    public Key quit = new BasicKey("Quit");
    public PauseKey pause = new PauseKey("Pause");

    private Game game;

    public keyboardHandler(Game game) {
        game.addKeyListener(this);
        this.game = game;
    }

    public void keyPressed(KeyEvent event) {
        toggleKey(event.getKeyCode(), true);
    }

    public void keyReleased(KeyEvent event) {
        toggleKey(event.getKeyCode(), false);
    }

    public void keyTyped(KeyEvent event) {
    }

    public void toggleKey(int keyCode, boolean isPressed) {
        switch (keyCode) {
            case KeyEvent.VK_UP :
                up.toggle(isPressed);
                break;
            case KeyEvent.VK_DOWN :
                down.toggle(isPressed);
                break;
            case KeyEvent.VK_LEFT :
                left.toggle(isPressed);
                break;
            case KeyEvent.VK_RIGHT :
                right.toggle(isPressed);
                break;
            case KeyEvent.VK_ESCAPE :
                quit.toggle(isPressed);
                break;
            case KeyEvent.VK_P :
                pause.toggle(isPressed);
                break;
            default :
                break;
        }
    }
}